<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>去除多余空格示例</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            background-color: #f0f0f0;
            color: #333;
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }

        .container {
            background-color: white;
            border-radius: 8px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            padding: 30px;
            width: 500px;
            text-align: center;
        }

        h1 {
            color: #3498db;
            font-size: 24px;
            margin-bottom: 20px;
        }

        p {
            font-size: 16px;
            margin-bottom: 20px;
        }

        textarea {
            width: 100%;
            height: 120px;
            padding: 10px;
            font-size: 16px;
            border: 1px solid #ccc;
            border-radius: 5px;
            resize: none;
            margin-bottom: 20px;
        }

        .output {
            background-color: #f9f9f9;
            border: 1px solid #ddd;
            border-radius: 5px;
            padding: 10px;
            font-size: 16px;
            min-height: 50px;
            display: flex;
            justify-content: center;
            align-items: center;
            color: #2ecc71;
            font-weight: bold;
            word-wrap: break-word;
            margin-top: 10px;
        }

        button {
            background-color: #3498db;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            font-size: 16px;
            transition: background-color 0.3s;
        }

        button:hover {
            background-color: #2980b9;
        }
    </style>
</head>

<body>

    <div class="container">
        <h1>去除多余空格示例</h1>
        <p>输入带有多余空格的文本，点击按钮去除多余的空格。</p>

        <textarea id="inputText" placeholder="请输入带有多余空格的文本..."></textarea>

        <button onclick="removeWhitespace()">去除空格</button>

        <div class="output" id="output">处理后的文本将在这里显示</div>

    </div>

    <script>
        // 定义 compactWhitespace 函数，去除多余的空格
        const compactWhitespace = str => str.replace(/\s{2,}/g, ' ');

        // 点击按钮时触发的函数
        function removeWhitespace() {
            const inputText = document.getElementById('inputText').value;
            const outputText = compactWhitespace(inputText);
            document.getElementById('output').textContent = outputText || '请输入带空格的文本';
        }
    </script>

</body>

</html>